<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use cmf\controller\HomeBaseController;
use app\portal\model\MessageModel;
use cmf\model\RedisData;

class MessageController extends HomeBaseController
{
	//留言
    public function Mess()
    {
    	if ($this->request->isPost()) {
    		$data = $this->request->param();
            
            $user_IP = isset($_SERVER["HTTP_VIA"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];
            $user_IP = ($user_IP) ? $user_IP : $_SERVER["REMOTE_ADDR"];
            if (!empty($data)){
                $RedisData = new RedisData();
                $Message = new MessageModel();
                if (!isset($data['name'])) $data['name'] = '未命名';
                if (!isset($data['gongsi'])) $data['gongsi'] = '未命名';
                if (!isset($data['phone'])) $data['phone'] = '';
                $data['time'] = time();
                $validateip = $RedisData->getRedis('IP_'.$user_IP);
                if (!$validateip) {
                    if ($Message->ComMessage($data)) {
                        $RedisData->setRedis('IP_'.$user_IP,$user_IP);
                        return $this->successful('提交成功！！');
                    }else{
                        return $this->fail(400,'提交失败！！');
                    }
                }else{
                    return $this->fail(400,'请忽重复提交！！');
                }
            }else{
                return $this->fail(400,'请忽提交空数据！！');
            }
    	}
    }

}
